package com.libertyville.domain.orgmng.validator;

import com.libertyville.domain.orgmng.TenantRepository;
import com.libertyville.domain.orgmng.TenantStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CommonValidator {
    private TenantRepository tenantRepository;

    @Autowired
    public CommonValidator(TenantRepository tenantRepository) {
        this.tenantRepository = tenantRepository;
    }

    public void validateTenant(Integer tenantId) {
        if (!tenantRepository.existsByIdAndStatus(tenantId, TenantStatus.EFFECTIVE))
            throw new RuntimeException("Failed to create Org because tenant id " + tenantId + " is invalid");
    }
}
